// pages/scoreComment/scoreComment.js
const app = getApp()
var service = require('../../util/service')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value:0,
    input:"",
    id:'',
    rprId:"",
    score:0,
    scorevalue:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.id = options.id;
    this.data.rprId = options.rprId;
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.rprId) {
      service.AJAX(`smc/dim/ScopeRel/listScopeRel.json?$rprId=${this.data.rprId}`, {}, res => {
        if (res.length > 0) {
          this.setData({
            'score': res[0].scopeNumber,
            'scorevalue': res[0].recordScopeInfo
          })
        }
      }, err => { }, 'GET', true)
    }

  },
  slider2change:function(e){
    this.setData({
      'value': e.detail.value
    })
  },
  bindKeyInput:function(e){
    this.data.input = e.detail.value
  },
  bindFormSubmit:function(){
    var user = app.userInfo;
    var score = {
      relType:'Provider',
      relId:this.data.id,
      recordScopeInfo: this.data.input || this.data.scorevalue,
      userId: user.buyId,
      scopeNumber: this.data.value || this.data.score
    }
    if (this.data.rprId){
      score.rprId = this.data.rprId;
      service.AJAX(`smc/dim/ScopeRel/updScopeRel.do`, score, res => {
        console.log(res);
        wx.showToast({
          title: "点评成功",
          icon: 'succes',
          duration: 1000,
          mask: true
        })
        wx.navigateBack({
          delta: 1
        })
      }, err => { }, "POST");
    }else{
      service.AJAX(`smc/dim/ScopeRel/addScopeRel.do`, score, res => {
        console.log(res);
        wx.showToast({
          title: "点评成功",
          icon: 'succes',
          duration: 1000,
          mask: true
        })
        wx.navigateBack({
          delta: 1
        })
      }, err => { }, "POST");
    }
    
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})